package org.example.struct.array;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * @author liyishan
 * @date 2023/8/24 10:56
 * @apiNote
 */

public class M02FindRepeatNumber {

    public static void main(String[] args) {
        int[] nums ={2, 3, 1, 0, 2, 5, 3};
        int count = test(nums);
        System.out.println(count);
    }

    public static int test(int[] nums) {
        int n = nums.length;
        Map<Integer,Integer> map = new HashMap<>();
        for(int i = 0 ; i<n;i++){
            map.put(nums[i],map.getOrDefault(nums[i],0)+1);
        }
        for(Map.Entry<Integer,Integer> entry:map.entrySet()){
            if(entry.getValue()>1){
                return entry.getKey();
            }
        }
        return 0;
    }
    public static int test1(int[] nums) {
        int n = nums.length;
        Set<Integer> set = new HashSet<>();
        for(int i = 0; i<n;i++){
            if(!set.add(nums[i])){
                return nums[i];
            }
        }
        return 0;
    }


}
